package ltesim.editors.helper;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

/**
 * Form Helper
 * 
 * @author xirka
 * 
 */
public class LFormHelper {

	private final static String OUTOFBOUNDCONTENT = "???";

	public LFormHelper() {
	}

	/**
	 * Create a text input on Composite com, using FormToolkit toolkit,<br/>
	 * and default content defContent
	 * 
	 * @param com
	 * @param toolkit
	 * @param defContent
	 * @return Text
	 */
	public static Text createTextInput(Composite com, FormToolkit toolkit,
			String defContent) {
		Text text = toolkit.createText(com, defContent);
		return text;
	}

	/**
	 * Create a combo box on Composite com, using FormToolkit toolkit, <br/>
	 * with available selections comboSels , and default content defContent
	 * 
	 * @param com
	 * @param toolkit
	 * @param comboSels
	 * @param defContent
	 * @return Combo
	 */
	public static Combo createCombo(Composite com, FormToolkit toolkit,
			String[] comboSels, String defContent) {
		Combo combo = new Combo(com, SWT.READ_ONLY | SWT.FLAT);
		for (String sel : comboSels) {
			combo.add(sel);
		}
		combo.setText(defContent);
		return combo;
	}

	/**
	 * Create a combo box on Composite com, using FormToolkit toolkit, <br/>
	 * with available selections comboSels , and default content
	 * comboSels[defContentIdx]
	 * 
	 * @param com
	 * @param toolkit
	 * @param comboSels
	 * @param defContentIdx
	 * @return Combo
	 */
	public static Combo createCombo(Composite com, FormToolkit toolkit,
			String[] comboSels, int defContentIdx) {
		String defContent;
		if (defContentIdx >= 0 && defContentIdx < comboSels.length) {
			defContent = comboSels[defContentIdx];
		} else {
			defContent = OUTOFBOUNDCONTENT;
		}
		return createCombo(com, toolkit, comboSels, defContent);

	}

}
